//#include "stdafx.h"
#include "lock.h"

#ifdef WIN32
CLock::CLock()
{
	InitializeCriticalSection(&m_cs);
}

CLock::~CLock()
{
	DeleteCriticalSection(&m_cs);
}

void CLock::Lock()
{
	EnterCriticalSection(&m_cs);
}

void CLock::UnLock()
{
	LeaveCriticalSection(&m_cs);
}
#elif defined(LINUX)
CLock::CLock()
{
#	ifdef __CYGWIN__
#		define PTHREAD_MUTEX_RECURSIVE_NP 1
#	endif

	pthread_mutexattr_init(&m_mutexattr);
	pthread_mutexattr_settype(&m_mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
	pthread_mutex_init(&m_mutex, &m_mutexattr);
	pthread_mutexattr_destroy(&m_mutexattr);
}

CLock::~CLock()
{
	pthread_mutex_destroy(&m_mutex);
}

void CLock::Lock()
{
	pthread_mutex_lock(&m_mutex);
}

void CLock::Unlock()
{
	pthread_mutex_unlock(&m_mutex);
}
#endif
